package flowSum;


import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @author caoxiaofeng
 * @date 2021-07-14 23:05
 */
public class FlowCountMapper extends Mapper<LongWritable,Text, Text,FlowBean> {

    Text k = new Text();
    FlowBean v = new FlowBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        //1	13736230513	192.196.100.1	www.atguigu.com	2481	24681	200
        //1. 获取一行
        String line = value.toString();
        //2. 切割\t
        String[] fields = line.split("\\t");

        //3. 封装对象
        k.set(fields[1]);

        long upFlow = Long.parseLong(fields[fields.length - 3]);
        long downFlow = Long.parseLong(fields[fields.length - 2]);
         v.set(upFlow,downFlow);
        //4. 写出
        context.write(k,v);
    }
}
